package org.willthink.controller.schedule;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.willthink.service.fileupload.FileUploadService;
import org.willthink.service.schedule.ScheduleService;
import org.willthink.vo.schedule.ScheduleVO;

@Controller
@RequestMapping("/schedule")
public class ScheduleController {
	
private ScheduleService scheduleServiceImpl; 
	
	public void setFileUploadServiceImpl(ScheduleService scheduleServiceImpl) {
		this.scheduleServiceImpl = scheduleServiceImpl;
	}

	@RequestMapping("/scheduleMain")
	public ModelAndView scheduleMain(HttpServletRequest request, HttpServletResponse response)
	{
		ModelAndView mav = new ModelAndView();
		
		Calendar cal = Calendar.getInstance();
		cal.setTimeZone(TimeZone.getTimeZone("Asia/Seoul"));
		String time = cal.getTime().toString();
		String year_title = time.substring(24, 28);
		String month_title = time.substring(4, 7);
		
		// 년, 월 화면 출력
		mav.addObject("year_title", year_title);
		if(month_title.equals("Jan"))
			mav.addObject("month_title", "1월");
		else if(month_title.equals("Feb"))
			mav.addObject("month_title", "2월");
		else if(month_title.equals("Mar"))
			mav.addObject("month_title", "3월");
		else if(month_title.equals("Apr"))
			mav.addObject("month_title", "4월");
		else if(month_title.equals("May"))
			mav.addObject("month_title", "5월");
		else if(month_title.equals("Jun"))
			mav.addObject("month_title", "6월");
		else if(month_title.equals("Jul"))
			mav.addObject("month_title", "7월");
		else if(month_title.equals("Aug"))
			mav.addObject("month_title", "8월");
		else if(month_title.equals("Sep"))
			mav.addObject("month_title", "8월");
		else if(month_title.equals("Oct"))
			mav.addObject("month_title", "10월");
		else if(month_title.equals("Nov"))
			mav.addObject("month_title", "11월");
		else if(month_title.equals("Dec"))
			mav.addObject("month_title", "12월");
		else
			mav.addObject("month_title", month_title);	
		
		List<String> list = new ArrayList<String>();
		list.add("123");
		list.add("123");
		list.add("123");
		mav.addObject("list", list);
		mav.setViewName("schedule/scheduleMain");
		
		ScheduleVO scheduleVO = new ScheduleVO();
		//scheduleServiceImpl.SelectTodaysSchedule(scheduleVO); //Null Point Exception 발생
		
		return mav;
	}
	
	@RequestMapping("/scheduleWrite")
	public ModelAndView scheduleWrite(HttpServletRequest request, HttpServletResponse response)
	{
		ModelAndView mav = new ModelAndView();
		ScheduleVO scheduleVO = new ScheduleVO();
		
		scheduleServiceImpl.InsertNewSchedule(scheduleVO);
		
		mav.setViewName("schedule/scheduleWrite");
		return mav;
	}
	
	@RequestMapping("/scheduleList")
	public ModelAndView scheduleList(HttpServletRequest request, HttpServletResponse response)
	{
		ModelAndView mav = new ModelAndView();
		ScheduleVO scheduleVO = new ScheduleVO();
		
		scheduleServiceImpl.DeleteRocordedSchedule(scheduleVO);
		
		mav.setViewName("schedule/scheduleList");
		return mav;
	}
	
	@RequestMapping("/scheduleRewrite")
	public ModelAndView scheduleRewrite(HttpServletRequest request, HttpServletResponse response)
	{
		ModelAndView mav = new ModelAndView();
		ScheduleVO scheduleVO = new ScheduleVO();
		
		scheduleServiceImpl.UpdateRecordedSchedule(scheduleVO);
		
		mav.setViewName("schedule/scheduleRewrite");
		return mav;
	}
}